﻿<%@ WebHandler Language="C#" Class="request" %>

using System;
using System.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
public class request : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        string yaoqingma = context.Request.Form["yaoqingma"];
        int obj = Convert.ToInt32(context.Request.Form["obj"]);
        int jiaoxue = Convert.ToInt32(context.Request.Form["jiaoxue"]);
        int neirong = Convert.ToInt32(context.Request.Form["neirong"]);
        int jishu = Convert.ToInt32(context.Request.Form["jishu"]);
        int chuangxin = Convert.ToInt32(context.Request.Form["chuangxin"]);
        int uid, yid,role;

        //查询邀请码存在并且可用，就继续，否则返回失败信息
        DataTable tb = SQLHelper.GetTable("select jici from yaoqingma where [yaoqingma]='"+yaoqingma+"'");
        if (tb.Rows.Count==0)
        {
            context.Response.Write("请确认邀请码是否正确(注意大小写)");
            context.Response.End();
            return;
        }
        if (Convert.ToInt32(tb.Rows[0][0]) >= 8)
        {
            context.Response.Write("这个邀请码已被使用");
            context.Response.End();
            return;
        }
        //查询名字和邀请码是否存在
        if (SQLHelper.GetTable("select * from pingfen where uid="+obj+" and yid = (select yid from yaoqingma where [yaoqingma]='" + yaoqingma + "')").Rows.Count > 0)
        {
            context.Response.Write("您已给打过分了");
            context.Response.End();
            return;
        }
        //查询是否可以打分
        int nowuid = Convert.ToInt32(SQLHelper.GetTable("select uid from control").Rows[0][0]);
        if (nowuid == 0)
        {
            context.Response.Write("打分系统已关闭");
            context.Response.End();
            return;
        }
        if (Convert.ToInt32(obj) != nowuid)
        {
            context.Response.Write("打分对象与当前不匹配，请重新选择");
            context.Response.End();
            return;
        }
        //查询各项分数是否在规定分数范围内
        //
        if (!(jiaoxue>=1 && jiaoxue<=40)) {
            context.Response.Write("总体设计评分必须范围1-40分");
            context.Response.End();
            return;
        }
        if (!(neirong >= 1 && neirong <= 30))
        {
            context.Response.Write("教学过程评分必须范围1-30分");
            context.Response.End();
            return;
        }
        if (!(jishu >= 1 && jishu <= 15))
        {
            context.Response.Write("教学效果评分必须范围1-15分");
            context.Response.End();
            return;
        }
        if (!(chuangxin >= 1 && chuangxin <= 15))
        {
            context.Response.Write("特色创新评分必须范围1-15分");
            context.Response.End();
            return;
        }
        uid = obj;

        tb = SQLHelper.GetTable("select yid,role from yaoqingma where [yaoqingma]='" + yaoqingma + "'");
        yid = Convert.ToInt32(tb.Rows[0][0]);
        role = Convert.ToInt32(tb.Rows[0][1]);
        //添加评分，
        string pingfen = string.Format("insert into pingfen values ({0},{1},{2},{3},{4},{5},{6},'{7}')",uid,yid,jiaoxue,neirong,jishu,chuangxin,(jiaoxue+neirong+jishu+chuangxin),DateTime.Now.ToString());
        string pingfen_judge = string.Format("insert into pingfen_judge values ({0},{1},{2},{3},{4},{5},{6},'{7}')",uid,yid,jiaoxue,neirong,jishu,chuangxin,(jiaoxue+neirong+jishu+chuangxin),DateTime.Now.ToString());
        if(role==1){
            if (SQLHelper.ExcuteSQL(pingfen_judge)>0 && SQLHelper.ExcuteSQL("update yaoqingma set jici=jici+1 where yid="+yid)>0) {
                context.Response.Write("您的打分已提交");
                context.Response.End();
            }
        }else{
            if (SQLHelper.ExcuteSQL(pingfen)>0 && SQLHelper.ExcuteSQL("update yaoqingma set jici=jici+1 where yid="+yid)>0) {
                context.Response.Write("您的打分已提交");
                context.Response.End();
            }
        }


    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}